package com.cloud.wyf.Service.Imp;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonArray;
import com.cloud.wyf.Entity.*;
import com.cloud.wyf.Feign.UserFeign;
import com.cloud.wyf.Mapper.LeaderScoreMapper;
import com.cloud.wyf.Mapper.LeaderShipScoreMapper;
import com.cloud.wyf.Mapper.MiddelScoreMapper;
import com.cloud.wyf.Mapper.OrdinaryScoreMapper;
import com.cloud.wyf.Service.VoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class VoteServiceImp implements VoteService {
//    @Autowired
//    DiscoveryClient discoveryClient;
    @Autowired
     UserFeign userFeign;
    @Autowired
    LeaderScoreMapper lsm;
    @Autowired
    MiddelScoreMapper msm;
    @Autowired
    OrdinaryScoreMapper osm;
    @Autowired
    LeaderShipScoreMapper leaderScoreMapper;

    public  void getI(){
        //String[] list={"0000005","0000007","0000064"};
        List<String> list=new ArrayList<>();
        list.add("0000005");
        list.add("0000007");
        list.add("0000064");
        String s = userFeign.queryLeaders(JSONObject.toJSONString(list));
        List<Leader> leaders = JSONArray.parseArray(s, Leader.class);
        System.out.println(leaders.toString());
//        List<ServiceInstance> instances = discoveryClient.getInstances("user-server");
//        if(instances.size()==0){
//            return;
//        }
//        ServiceInstance serviceInstance = instances.get(RandomUtil.randomInt(instances.size()));
    }

    @Override
    public List<LeaderShipScore> batchSelectLeaderShipByUAndP(List<String> leader, String part) {
        return leaderScoreMapper.batchSelectLeaderShipByUAndP(leader,part);
    }

    @Override
    public List<LeaderShipScore> selelctAllLeaderShipScore() {
        return leaderScoreMapper.selelctAllLeaderShipScore();
    }

    @Override
    public List<Leader> queryAllLeader(String token) {
        return JSONArray.parseArray(userFeign.queryAllLeader(token),Leader.class);
    }

    @Override
    public List<LeaderScore> selectLeaderScoreByMiddelId(String middelid) {
        return lsm.selectLeaderScoreByMiddelId(middelid);
    }

    @Override
    public List<OrdinaryScore> selectOrdinaryScoreByMid(String mid) {
        return osm.selectOrdinaryScoreByMid(mid);
    }

    @Override
    public List<Data> queryData(String token) {
        return JSONArray.parseArray(userFeign.queryData(token),Data.class);
    }

    @Override
    public List<Middel> queryAllMiddel(String token) {
        return JSONArray.parseArray(userFeign.queryAllMiddel(token),Middel.class);
    }

    @Override
    public List<Ordinary> queryAllOrdinary(String token) {
        return JSONArray.parseArray(userFeign.queryAllOrdinary(token),Ordinary.class);
    }

    @Override
    public int isAuth(String token) {
        String isAuth = userFeign.queryIsAuth(token);
        if("yes".equals(isAuth)) return 1;
        else if("no" .equals(isAuth)) return 0;
        else return -1;
    }

    @Override
    public List<Middel> getNeedVote(String token) {
        return JSONArray.parseArray(userFeign.queryNeedVote(token),Middel.class);
    }

    @Override
    public List<LeaderShip> getNeedLeaderShip(String token) {
        return JSONArray.parseArray(userFeign.queryNeedLeaderShip(token),LeaderShip.class);
    }

    @Override
    public List<LeaderShipScore> selelctLeaderShipScoreByUid(String uid) {
        return leaderScoreMapper.selelctLeaderShipScoreByUid(uid);
    }

    @Override
    public int addLeaderScoreMult(List<LeaderScore> list) {
        return lsm.addLeaderScoreMult(list);
    }

    @Override
    public int addMiddelScoreMult(List<MiddelScore> list) {
        return msm.addMiddelScoreMult(list);
    }

    @Override
    public int addOrdinaryScoreMult(List<OrdinaryScore> list) {
        return osm.addOrdinaryScoreMult(list);
    }

    @Override
    public int addLeaderShipScoreMult(List<LeaderShipScore> list) {
        return leaderScoreMapper.addLeaderShipScoreMult(list);
    }

    @Override
    public LeaderScore selectByLAndMId(String leaderid, String middelid) {
        return lsm.selectByLAndMId(leaderid,middelid);
    }

    @Override
    public MiddelScore selectByMAndMId(String mvoteid, String mid) {
        return msm.selectByMAndMId(mvoteid,mid);
    }

    @Override
    public OrdinaryScore selectByOAndMId(String oid, String mid) {
        return osm.selectByOAndMId(oid,mid);
    }

    @Override
    public LeaderShipScore selectLeaderShipByUAndP(String uid, String votepart) {
        return leaderScoreMapper.selectLeaderShipByUAndP(uid,votepart);
    }

    @Override
    public List<LeaderScore> selectLeaderScoreByUid(String leaderid) {
        return lsm.selectLeaderScoreByUid(leaderid);
    }

    @Override
    public List<MiddelScore> selectMiddelScoreByMid(String mid) {
        return msm.selectMiddelScoreByMId(mid);
    }

    @Override
    public List<OrdinaryScore> selecOrdinaryScoreByOid(String oid) {
        return osm.selectOrdinaryScoreByOId(oid);
    }

    @Override
    public int updateLeaderScore(LeaderScore leaderScore) {
        return lsm.updateLeaderScore(leaderScore);
    }

    @Override
    public int updateMiddelScore(MiddelScore middelScore) {
        return msm.updateLeaderScore(middelScore);
    }

    @Override
    public int updateOrdinaryScore(OrdinaryScore ordinaryScore) {
        return osm.updateLeaderScore(ordinaryScore);
    }

    @Override
    public int updateLeaderScoreQuit(String leaderid, String middelid) {
        return lsm.updateLeaderScoreQuit(leaderid,middelid);
    }

    @Override
    public int updateMiddelScoreQuit(String mvoteid, String mid) {
        return msm.updateMiddelScoreQuit(mvoteid,mid);
    }

    @Override
    public int updateOrdinaryScoreQuit(String oid, String mid) {
        return osm.updateOrdinaryScoreQuit(oid,mid);
    }

    @Override
    public int updateLeaderShipScore(LeaderShipScore leaderScore) {
        return leaderScoreMapper.updateLeaderShipScore(leaderScore);
    }

    @Override
    public int updateLeaderShipScoreQuit(String uid, String votepart) {
        return leaderScoreMapper.updateLeaderShipScoreQuit(uid,votepart);
    }

    @Override
    public List<LeaderScore> selectLeaderScoreByOid(String middelid) {
        return lsm.selectLeaderScoreByMiddelId(middelid);
    }

    @Override
    public List<OrdinaryScore> selectOrdinaryScoreByOid(String oid) {
        return osm.selectOrdinaryScoreByOid(oid);
    }

}
